package cn.wisenergy.pai.monitor.linux.parser;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;


public class Disk implements Serializable{
	
	private static final long serialVersionUID = 6665754288314558582L;
	//磁盘读取速率
	private float diskread =0;
	//磁盘写速率
	private float diskwrite=0;

	public float getDiskread() {
		return diskread;
	}
	public void setDiskread(float diskread) {
		this.diskread = diskread;
	}
	public float getDiskwrite() {
		return diskwrite;
	}
	public void setDiskwrite(float diskwrite) {
		this.diskwrite = diskwrite;
	}
	@Override
	public byte[] toBytes() throws IOException {
		ByteArrayOutputStream bytesOutput=new ByteArrayOutputStream();
		DataOutputStream dataOutput=new DataOutputStream(bytesOutput);
		dataOutput.writeFloat(diskread);
		dataOutput.writeFloat(diskwrite);
		byte[] result=bytesOutput.toByteArray();
		dataOutput.close();
		bytesOutput.close();
		return result;
	}
	@Override
	public void toObject(byte[] ab) throws IOException {
		ByteArrayInputStream bytesInput=new ByteArrayInputStream(ab);
		DataInputStream dataInput=new DataInputStream(bytesInput);
		if(dataInput.available()>0){
			diskread=dataInput.readFloat();
		}
		if(dataInput.available()>0){
			diskwrite=dataInput.readFloat();
		}
		dataInput.close();
		bytesInput.close();
		
	}
	@Override
	public String toString() {
		return "Disk [diskread=" + diskread + ", diskwrite=" + diskwrite + "]";
	}
	
}
